/**
 * Created by cqb32_000 on 2016-12-21.
 */

var fork = require('child_process').fork;
var getTiltWorker = fork('./workers/getTiltWorker.js');
var times, index = 0;
var retTimes = [];

var GetBestTilt = function(ts){
    times = ts;

    next();
};

getTiltWorker.on("message", (data)=>{
    index++;
    if(!data.time.tilt){
        next();
        return;
    }
    //未全覆盖
    retTimes.push(data.time);
    if(data.lastarea != 0 ){
        next();
    }else{

    }
});

function next(){
    if(index < times.length) {
        var time = times[index];
        getTiltWorker.send(time);
    }
}


module.exports = GetBestTilt;